﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HCMUS_SearchService_Group2;
using NUnit.Framework;

namespace HCM_SS_UnitTest.Test
{
    [TestFixture, Description("Kiểm thử công cụ tìm kiếm mặc định(phần 1)")]
    [Category("DefaultSearchTest(Part1)")]
    public partial class DefaultSearchTest
    {
        private const int SERVICEDEFAULT = 0;
        private const int NOTRESULTCOUNT = 0;
        private static string stringEmpty = string.Empty;
        private static string stringNull = null;
        private DefaultSearchEngine defSearch;
        /////////////////////////////////////////////////
        /// \brief Hàm khởi tạo cho toàn class
        /// \param[in] Không.
        /// \returns Không.
        /// \details <h3>Khởi tạo các biến data cho unit test</h3>
        /////////////////////////////////////////////////

        [TestFixtureSetUp]
        public void FixtureSetUp()
        {
            defSearch = new DefaultSearchEngine();
        }

        /////////////////////////////////////////////////
        /// \brief Hàm hủy cho mỗi toàn class
        /// \param[in] Không.
        /// \returns Không.
        /// \details <h3>Hủy các biến data cho unit test</h3>
        /////////////////////////////////////////////////
        [TestFixtureTearDown]
        public void FixtureTearDown()
        {
        }

        /////////////////////////////////////////////////
        /// \brief Hàm kiểm tra phương thức Search
        /// \param[in] Không.
        /// \returns Không.
        /// \details <h3>Kiểm tra phương thức có kiểm tra đối số 
        /// input Null hay không cho phương thức Search</h3>
        /////////////////////////////////////////////////
        [Test]
        public void SearchStringNullInputTest()
        {
            var result = this.defSearch.Search(stringNull, SERVICEDEFAULT);
            Assert.AreEqual(NOTRESULTCOUNT, result.Count);
        }

        /////////////////////////////////////////////////
        /// \brief Hàm kiểm tra phương thức Search
        /// \param[in] string.
        /// \returns Không.
        /// \details <h3>Kiểm tra kết quả trả về cho phương thức
        /// Search</h3>
        /////////////////////////////////////////////////
        [Test]
        [TestCase("atm Nguyen Van Cu", SERVICEDEFAULT, 11)]
        [TestCase("cafe tinh lo 10", 1, NOTRESULTCOUNT)]
        [TestCase(" Paster ", 1, 4)]
        [TestCase("quan 5 phuong 6", 5, 4)]
        [TestCase("nha hang Tan Phu", 0, 31)]
        [TestCase("pho", 0, 86)]
        [TestCase("pho cong hoa", 0, 74)]
        [TestCase("truong nguyen van cu", 0, 6)]
        [TestCase("atm xyzsdsa", 0, 0)]
        public void SearchHaveResultReturnTest(string testStr, int serviceID, int expected)
        {
            Type p = typeof(DefaultSearchEngine);
            MemberInfo[] mem = p.GetMembers();
            MethodInfo method = p.GetMethod(mem[2].Name);
            object[] obj = new object[2];
            obj[0] = testStr;
            obj[1] = serviceID;
            var res = method.Invoke(this.defSearch, obj);
            Assert.AreEqual(expected, ((List<ContentDataDTO>)res).Count);
        }
    }
}
